package org.csu.mypetstore.web.servlets;

import com.github.wxpay.sdk.WechatOrder;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class GetQRCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletOutputStream outputStream = resp.getOutputStream();

        WechatOrder wechatOrder = (WechatOrder)req.getSession().getAttribute("wechatOrder");

        resp.setContentType("image/*");
        ImageIO.write(wechatOrder.getQRCode(), "png", outputStream);
        outputStream.close();
    }
}
